package com.atguigui.leetcode1;

import java.util.HashMap;
import java.util.Map;

/**
 * 2325.解密消息
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/2/1 8:52
 */
public class P2325DecodeTheMessage {

    public static void main(String[] args) {
        Solution solution = new P2325DecodeTheMessage().new Solution();
        // TO TEST
    }

    class Solution {
        public String decodeMessage(String key, String message) {

            char cur = 'a';

            Map<Character, Character> rules = new HashMap<>();

            for (int i = 0; i < key.length(); i++) {
                char c = key.charAt(i);
                if (c != ' ' && !rules.containsKey(c)) {
                    rules.put(c, cur);
                    ++cur;
                }
            }


            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < message.length(); i++) {
                char c = message.charAt(i);
                if (c != ' ') {
                    c = rules.get(c);
                }
                sb.append(c);
            }

            return sb.toString();
        }
    }
}
